package com.net.okhttphelper.http;

/**
 * 网络请求配置
 * @author jie
 */
public class HttpConfig {

    /**
     * 网络请求默认最大等待时间
     */
    private static final long HTTP_REQUEST_MAX_WAIT_TIME = 40000;

    /**
     * 设置服务器地址
     */
    private final String baseUrl;
    /**
     * 是否打印log
     */
    private final boolean isShowLog;
    /**
     * 请求超时时间
     */
    private final long readTimeout;
    /**
     * 连接超时时间
     */
    private final long connectTimeout;
    /**
     * 默认文件保存文件夹地址
     */
    private final String saveFilePath;

    public HttpConfig(Builder builder) {
        this.baseUrl = builder.baseUrl;
        this.isShowLog = builder.isShowLog;
        this.readTimeout = builder.readTimeout;
        this.connectTimeout = builder.connectTimeout;
        this.saveFilePath = builder.saveFilePath;
    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public boolean isShowLog() {
        return isShowLog;
    }

    public long getReadTimeout() {
        return readTimeout;
    }

    public long getConnectTimeout() {
        return connectTimeout;
    }

    public String getSaveFilePath() {
        return saveFilePath;
    }

    public static class Builder {

        // 服务器地址(必须填写)
        private String baseUrl;
        // 是否打印log
        private boolean isShowLog = false;
        // 默认文件保存文件夹地址(必须填写)
        private String saveFilePath;
        // 请求超时时间
        private long readTimeout = HTTP_REQUEST_MAX_WAIT_TIME;
        // 连接超时时间
        private long connectTimeout = HTTP_REQUEST_MAX_WAIT_TIME;

        public HttpConfig.Builder setShowLog(boolean showLog) {
            this.isShowLog = showLog;
            return this;
        }

        public HttpConfig.Builder setReadTimeout(long readTimeout) {
            this.readTimeout = readTimeout;
            return this;
        }

        public HttpConfig.Builder setConnectTimeout(long connectTimeout) {
            this.connectTimeout = connectTimeout;
            return this;
        }

        public HttpConfig build(String baseUrl, String saveFilePath){
            this.baseUrl = baseUrl;
            this.saveFilePath = saveFilePath;
            return new HttpConfig(this);
        }

    }

}
